package avpc

import (
	"errors"
	"fmt"

	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
)

type IspSubnet struct {
	IspSubnetCIDR string `json:"IspSubnetCIDR"`
	IspSubnetID   string `json:"IspSubnetID"`
}

type Isp struct {
	IspDescription string      `json:"IspDescription"`
	IspId          string      `json:"IspId"`
	IspSubnet      []IspSubnet `json:"IspSubnet"`
	IspName        string      `json:"IspName"`
}

type DescribeIspResponse struct {
	*responses.BaseResponse
	TotalCount int `json:"TotalCount"`
	Isp        struct {
		Isp []Isp `json:"Isp"`
	} `json:"Isp"`
	PageNumber int    `json:"PageNumber"`
	RequestId  string `json:"RequestId"`
	PageSize   int    `json:"PageSize"`
}

func (d *DescribeIspResponse) FirstIspId() (string, error) {
	if len(d.Isp.Isp) == 0 {
		return "", errors.New("no Isp elements")
	}
	return d.Isp.Isp[0].IspId, nil
}

// CreateDescribeImagesResponse creates a response to parse from DescribeImages response
func CreateDescribeIspResponse() (response *DescribeIspResponse) {

	response = &DescribeIspResponse{
		BaseResponse: &responses.BaseResponse{},
	}
	return
}

func (c *Client) DescribeIsp(req *requests.RpcRequest) (response *DescribeIspResponse, err error) {
	// tea.String("hello")
	client := c.Client
	req.Port = c.Port
	req.Method = "GET"
	resp := CreateDescribeIspResponse()
	err = client.DoAction(req, resp)
	if err != nil {
		return nil, fmt.Errorf("error DescribeInstanceStatus %w", err)
	}
	return resp, nil
}
